
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>ES6 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Landen">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-toggle-chapters/toggle.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-image-captions/image-captions.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="ES6-ES11.html" />
    
    
    <link rel="prev" href="nvm.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../01html/html简介.html">
            
                <a href="../01html/html简介.html">
            
                    
                    HTML
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../01html/01html.html">
            
                <a href="../01html/01html.html">
            
                    
                    a链接、图片
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../01html/02html.html">
            
                <a href="../01html/02html.html">
            
                    
                    列表、表格、表单
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../01html/h5新增.html">
            
                <a href="../01html/h5新增.html">
            
                    
                    h5新增
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../02css/css简介.html">
            
                <a href="../02css/css简介.html">
            
                    
                    CSS
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../02css/居中、省略、清浮.html">
            
                <a href="../02css/居中、省略、清浮.html">
            
                    
                    居中、省略、清浮
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../02css/浮动和定位.html">
            
                <a href="../02css/浮动和定位.html">
            
                    
                    浮动和定位
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../02css/变换、过渡、动画.html">
            
                <a href="../02css/变换、过渡、动画.html">
            
                    
                    变换、过渡、动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../02css/sass和rem.html">
            
                <a href="../02css/sass和rem.html">
            
                    
                    sass和rem
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../02css/flex、media、栅格化.html">
            
                <a href="../02css/flex、media、栅格化.html">
            
                    
                    flex、media、栅格化
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="js简介.html">
            
                <a href="js简介.html">
            
                    
                    JavaScript
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="数据类型.html">
            
                <a href="数据类型.html">
            
                    
                    数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="字符串.html">
            
                <a href="字符串.html">
            
                    
                    字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="数组.html">
            
                <a href="数组.html">
            
                    
                    数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="回流和重绘.html">
            
                <a href="回流和重绘.html">
            
                    
                    回流和重绘
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="浏览器的渲染过程.html">
            
                <a href="浏览器的渲染过程.html">
            
                    
                    浏览器的渲染过程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="十大排序算法.html">
            
                <a href="十大排序算法.html">
            
                    
                    十大排序算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="对象的构建.html">
            
                <a href="对象的构建.html">
            
                    
                    对象的构建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="this.html">
            
                <a href="this.html">
            
                    
                    this
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="bind&call&apply.html">
            
                <a href="bind&call&apply.html">
            
                    
                    bind&call&apply
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="函数.html">
            
                <a href="函数.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11" data-path="变量提升.html">
            
                <a href="变量提升.html">
            
                    
                    变量提升
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.12" data-path="作用域.html">
            
                <a href="作用域.html">
            
                    
                    作用域
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.13" data-path="对象.html">
            
                <a href="对象.html">
            
                    
                    对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.14" data-path="存储.html">
            
                <a href="存储.html">
            
                    
                    存储
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.15" data-path="事件.html">
            
                <a href="事件.html">
            
                    
                    事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.16" data-path="图片预览.html">
            
                <a href="图片预览.html">
            
                    
                    图片预览
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.17" data-path="防抖节流.html">
            
                <a href="防抖节流.html">
            
                    
                    防抖节流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.18" data-path="同步异步.html">
            
                <a href="同步异步.html">
            
                    
                    同步异步
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.19" data-path="babel入门.html">
            
                <a href="babel入门.html">
            
                    
                    babel入门
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.20" data-path="nvm.html">
            
                <a href="nvm.html">
            
                    
                    nvm
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.4.21" data-path="ES6.html">
            
                <a href="ES6.html">
            
                    
                    ES6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.22" data-path="ES6-ES11.html">
            
                <a href="ES6-ES11.html">
            
                    
                    ES6-ES11
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >ES6</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
                                <section class="normal markdown-section">
                                
                                <h2 id="let">let</h2>
<ul>
<li><p>&#x7C7B;&#x4F3C;&#x4E8E;var,&#x7528;&#x4E8E;&#x58F0;&#x660E;&#x53D8;&#x91CF;</p>
</li>
<li><p>&#x4F7F;&#x7528;let&#x58F0;&#x660E;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x4F1A;&#x6709;&#x5757;&#x7EA7;&#x4F5C;&#x7528;&#x57DF;&#x7684;&#x6982;&#x5FF5;&#xFF0C;&#x53D8;&#x91CF;&#x4F1A;&#x9650;&#x5236;&#x5728;&#x53D8;&#x91CF;&#x6240;&#x5728;&#x7684;&#x4EE3;&#x7801;&#x5757;(&#x51FD;&#x6570;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x5757;&#x7EA7;&#x4F5C;&#x7528;&#x57DF;)&#x5185;</p>
</li>
</ul>
<pre><code class="lang-js"><span class="hljs-comment">// &#x5728;&#x5757;&#x7EA7;&#x4F5C;&#x7528;&#x57DF;&#x5185;&#x58F0;&#x660E;&#x7684;var&#x53D8;&#x91CF;&#xFF0C;&#x4F1A;&#x5FFD;&#x7565;&#x5757;&#x7EA7;&#x4F5C;&#x7528;&#x57DF;</span>
<span class="hljs-comment">// &#x6C61;&#x67D3;&#x5916;&#x90E8;&#x4F5C;&#x7528;&#x57DF;</span>
<span class="hljs-comment">// for (var i = 0; i &lt; 5; i++) {}</span>
<span class="hljs-comment">// console.log(i);</span>

<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">5</span>; i++) {}
<span class="hljs-comment">// console.log(i) //not defined</span>
</code></pre>
<ol>
<li>&#x4E0D;&#x5B58;&#x5728;&#x53D8;&#x91CF;&#x63D0;&#x5347;</li>
</ol>
<pre><code class="lang-js"><span class="hljs-comment">// &#x4F7F;&#x7528;let const&#x58F0;&#x660E;&#x53D8;&#x91CF;&#x65F6;&#xFF0C;&#x4E0D;&#x5B58;&#x5728;&#x53D8;&#x91CF;&#x63D0;&#x5347;&#xFF0C;&#x5728;&#x53D8;&#x91CF;&#x5B8C;&#x6210;&#x5B9A;&#x4E49;&#x524D;&#xFF0C;&#x4F7F;&#x7528;&#x8BE5;&#x53D8;&#x91CF;&#x4F1A;&#x62A5;&#x9519;</span>

<span class="hljs-comment">// &#x5B58;&#x5728;&#x6682;&#x65F6;&#x6027;&#x6B7B;&#x533A;(TDZ):&#x53D8;&#x91CF;&#x6240;&#x5728;&#x4F5C;&#x7528;&#x57DF;&#x7684;&#x9876;&#x90E8;&#x5230;&#x53D8;&#x91CF;&#x58F0;&#x660E;&#x4E4B;&#x95F4;</span>

<span class="hljs-comment">// tip:&#x53D8;&#x91CF;&#x53C2;&#x4E0E;&#x9884;&#x89E3;&#x6790;&#xFF0C;&#x4F46;&#x662F;&#x6807;&#x8BC6;&#x7B26;&#x4E0D;&#x4F1A;&#x63D0;&#x5347;&#x81F3;&#x9876;&#x90E8;&#x58F0;&#x660E;</span>
<span class="hljs-comment">// &#x6CE8;&#x610F;&#xFF1A;&#x4F4E;&#x7248;&#x672C; v8 &#x5F15;&#x64CE;&#x5BF9;let const&#x5728;&#x5B9A;&#x4E49;&#x524D;&#x4F7F;&#x7528;&#x8F93;&#x51FA;not defined</span>
<span class="hljs-built_in">console</span>.log(alex); <span class="hljs-comment">// &apos;undefined&apos;</span>
<span class="hljs-comment">// console.log(bluej); // Cannot access &apos;bluej&apos; before initialization</span>
<span class="hljs-keyword">let</span> bluej = <span class="hljs-string">&quot;bluej&quot;</span>;
<span class="hljs-keyword">var</span> alex = <span class="hljs-string">&apos;alex&apos;</span>;
</code></pre>
<ol>
<li>&#x4E0D;&#x5141;&#x8BB8;&#x91CD;&#x590D;&#x58F0;&#x660E;</li>
</ol>
<pre><code class="lang-js"><span class="hljs-comment">// &#x4F7F;&#x7528;let const&#x58F0;&#x660E;&#x7684;&#x53D8;&#x91CF;&#x6807;&#x8BC6;&#x7B26;&#x4E0D;&#x5141;&#x8BB8;&#x91CD;&#x590D;&#x58F0;&#x660E;&#xFF1B;</span>
<span class="hljs-comment">// (&#x907F;&#x514D;&#x5728;&#x5F00;&#x53D1;&#x4E2D;&#xFF0C;&#x4F7F;&#x7528;var&#x91CD;&#x590D;&#x58F0;&#x660E;&#x5BFC;&#x81F4;&#x8986;&#x76D6;&#x539F;&#x6709;&#x540C;&#x540D;&#x53D8;&#x91CF;&#x5E26;&#x6765;&#x7684;&#x5F71;&#x54CD;)</span>
<span class="hljs-keyword">var</span> a = <span class="hljs-number">10</span>;
<span class="hljs-keyword">var</span> a = <span class="hljs-number">20</span>;
<span class="hljs-built_in">console</span>.log(a);
<span class="hljs-keyword">let</span> b = <span class="hljs-number">88</span>;
<span class="hljs-comment">// let b = 99; //Identifier &apos;b&apos; has already been declared</span>
</code></pre>
<h2 id="const">const</h2>
<ul>
<li>&#x4F7F;&#x7528;const&#x58F0;&#x660E;&#x7B26;&#x65F6;&#xFF0C;&#x5B9A;&#x4E49;&#x53D8;&#x91CF;&#x4E3A;&#x5E38;&#x91CF;&#xFF1B;</li>
<li>&#x5BF9;&#x4E8E;&#x57FA;&#x672C;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF0C;&#x65E0;&#x6CD5;&#x91CD;&#x65B0;&#x8D4B;&#x503C;&#xFF0C;&#x4F1A;&#x62A5;&#x9519;&#xFF1B;</li>
<li>&#x5BF9;&#x4E8E;&#x5F15;&#x7528;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF0C;&#x53EF;&#x4EE5;&#x4FEE;&#x6539;&#x5806;&#x5185;&#x5B58;&#x5185;&#x5BB9;&#xFF0C;&#x4F46;&#x662F;&#x4E0D;&#x5141;&#x8BB8;&#x4FEE;&#x6539;&#x5185;&#x5B58;&#x6307;&#x5411;</li>
</ul>
<h2 id="&#x7ED3;&#x6784;&#x8D4B;&#x503C;">&#x7ED3;&#x6784;&#x8D4B;&#x503C;</h2>
<ul>
<li><p>&#x6309;&#x7167;&#x4E00;&#x5B9A;&#x7684;&#x5339;&#x914D;&#x6A21;&#x5F0F;&#xFF0C;&#x53D6;&#x51FA;&#x503C;&#x8D4B;&#x4E88;&#x53D8;&#x91CF;&#xFF1B;</p>
</li>
<li><p>&#x6570;&#x7EC4;&#x7684;&#x89E3;&#x6784;&#x8D4B;&#x503C;</p>
<ul>
<li>&#x6309;&#x7167;&#x6570;&#x7EC4;&#x7684;&#x987A;&#x5E8F;&#x8D4B;&#x4E88;&#x5DE6;&#x4FA7;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x6309;&#x4F4D;&#x7F6E;&#x4E00;&#x4E00;&#x5BF9;&#x5E94;</li>
<li>&#x5982;&#x679C;&#x6570;&#x636E;&#x6E90;&#x4E3A;&#x591A;&#x7EF4;&#x6570;&#x7EC4;&#xFF0C;&#x4E00;&#x6837;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x76F8;&#x5E94;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x8FDB;&#x884C;&#x89E3;&#x6784;&#x8D4B;&#x503C;</li>
</ul>
</li>
<li><p>&#x5BF9;&#x8C61;&#x7684;&#x89E3;&#x6784;&#x8D4B;&#x503C;</p>
<ul>
<li>&#x6839;&#x636E;&#x5339;&#x914D;&#x6A21;&#x5F0F;&#x627E;&#x5230;&#x540C;&#x540D;&#x6570;&#x636E;&#x7ED9;&#x5230;&#x76F8;&#x5E94;&#x53D8;&#x91CF;&#xFF0C;&#x4E0D;&#x5173;&#x5FC3;&#x5C5E;&#x6027;&#x7684;&#x987A;&#x5E8F;&#xFF0C;</li>
<li>&#x53EA;&#x5173;&#x5FC3;&#x5C5E;&#x6027;&#x540D;&#x79F0;&#x662F;&#x5426;&#x5BF9;&#x5E94;&#xFF0C;&#x5982;&#x679C;&#x627E;&#x4E0D;&#x5230;&#x5BF9;&#x5E94;&#x503C;&#xFF0C;&#x5219;&#x4E3A;undefined</li>
<li>&#x4F7F;&#x7528; : &#x63D0;&#x4F9B;&#x522B;&#x540D;</li>
<li><p>&#x591A;&#x4E2A;&#x5C5E;&#x6027;&#x540D;&#x76F8;&#x540C;&#x7684;&#x5BF9;&#x8C61;&#x8FDB;&#x884C;&#x7ED3;&#x6784;&#x65F6;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x63D0;&#x4F9B;&#x522B;&#x540D;&#xFF0C;&#x4F1A;&#x6709;&#x53D8;&#x91CF;&#x51B2;&#x7A81;</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> {
   name: zjName,
   hobby: zjHobby
} = obj1;
<span class="hljs-keyword">let</span> {
   hobby: jqHobby,
   name: jqName
} = obj2;
<span class="hljs-built_in">console</span>.log(zjName, jqName)
</code></pre>
</li>
</ul>
</li>
</ul>
<h2 id="&#x4F7F;&#x7528;&#x7ED3;&#x6784;&#x8D4B;&#x503C;&#x5C01;&#x88C5;ajax">&#x4F7F;&#x7528;&#x7ED3;&#x6784;&#x8D4B;&#x503C;&#x5C01;&#x88C5;ajax</h2>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">_ajax</span>(<span class="hljs-params">{method = &quot;get&quot;,url,callback}</span>)</span>{
    <span class="hljs-keyword">let</span> xhr = <span class="hljs-keyword">new</span> XMLHttpRequest();
    xhr.open(method,url);
    xhr.addEventListener(<span class="hljs-string">&quot;readystatechange&quot;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-keyword">if</span>(xhr.readyState == <span class="hljs-number">4</span> &amp;&amp; xhr.status == <span class="hljs-number">200</span>){
            callback(<span class="hljs-built_in">JSON</span>.parse(xhr.response));
        }
    })
    xhr.send();
}
<span class="hljs-comment">// &#x4F7F;&#x7528;</span>
_ajax({
    <span class="hljs-comment">// method: &quot;post&quot;,</span>
    url: <span class="hljs-string">&apos;xxx&apos;</span>,
    callBack: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{

    }
})
</code></pre>
<h2 id="promise">promise</h2>
<ul>
<li>&#x89E3;&#x51B3;&#x4F20;&#x7EDF;&#x5F02;&#x6B65;&#x7F16;&#x7A0B;&#x4E2D;&#x56DE;&#x8C03;&#x5D4C;&#x5957;&#x5E26;&#x6765;&#x7684;&#x4E0D;&#x4FBF;</li>
<li>Promise &#x5B9E;&#x4F8B;&#x6709;&#x4E09;&#x79CD;&#x72B6;&#x6001;&#xFF0C;&#x5206;&#x522B;&#x662F;&#xFF1A;<ol>
<li>pending(&#x5B9E;&#x4F8B;&#x5316;&#x51FA;&#x6765;&#x7684;&#x9ED8;&#x8BA4;&#x72B6;&#x6001;)</li>
<li>resolve(&#x6210;&#x529F;)</li>
<li>reject(&#x5931;&#x8D25;)</li>
</ol>
</li>
<li>&#x6CE8;&#x610F;&#xFF1A;new Promise &#x7684;&#x8FC7;&#x7A0B;&#x662F;&#x540C;&#x6B65;&#x7684;&#xFF0C;.then &#x662F;&#x5F02;&#x6B65;&#x7684;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> pro = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(() =&gt; {});
<span class="hljs-built_in">console</span>.log(pro); <span class="hljs-comment">// {} &#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x7684;&#x72B6;&#x6001;&#x4E3A; pending;</span>
<span class="hljs-comment">// &#x5982;&#x679C;&#x4E0D;&#x4E3B;&#x52A8; &#x626D;&#x8F6C;/&#x6539;&#x53D8; &#x5B9E;&#x4F8B;&#x7684;&#x72B6;&#x6001;&#xFF0C;&#x5219;&#x4E00;&#x76F4;&#x4E3A; pending</span>

<span class="hljs-keyword">let</span> pro1 = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>((resolve, reject) =&gt; {
<span class="hljs-comment">// resolve: promise &#x5BF9;&#x8C61;&#x5185;&#x7F6E;&#x51FD;&#x6570;&#xFF0C;&#x7528;&#x4E8E;&#x626D;&#x8F6C;promise&#x81F3;&#x6210;&#x529F;</span>
<span class="hljs-comment">// reject&#xFF1A;promise &#x5BF9;&#x8C61;&#x5185;&#x7F6E;&#x51FD;&#x6570;&#xFF0C;&#x7528;&#x4E8E;&#x626D;&#x8F6C;promise&#x81F3;&#x5931;&#x8D25;</span>
resolve();
<span class="hljs-comment">// &#x4E00;&#x65E6;&#x6267;&#x884C; resolve/reject&#xFF0C;&#x90A3;&#x4E48;promise&#x5B9E;&#x4F8B;&#x72B6;&#x6001;&#x6539;&#x53D8;&#x540E;&#x5C31;&#x4F1A;&#x88AB;&#x51DD;&#x56FA;&#xFF0C;&#x4E0D;&#x80FD;&#x518D;&#x7EE7;&#x7EED;&#x6539;&#x53D8;&#x72B6;&#x6001;&#xFF0C;&#x6240;&#x4EE5;&#x4E0B;&#x65B9;&#x7684;reject&#x65E0;&#x6548;</span>
reject();
});
<span class="hljs-built_in">console</span>.log(pro1);

<span class="hljs-comment">// &#x4F7F;&#x7528; then &#x65B9;&#x6CD5;&#x6765;&#x4E3A; promise &#x72B6;&#x6001;&#x6539;&#x53D8;&#x540E;&#x6DFB;&#x52A0;&#x76F8;&#x5E94;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;</span>
<span class="hljs-comment">// &#x6CE8;&#x610F;&#xFF1A;then &#x4E3A;&#x5F02;&#x6B65;&#x65B9;&#x6CD5;&#xFF0C;&#x53EA;&#x6709;&#x5F53;promise&#x5B9E;&#x4F8B;&#x72B6;&#x6001;&#x6539;&#x53D8;&#x624D;&#x4F1A;&#x89E6;&#x53D1;</span>
<span class="hljs-keyword">let</span> pro2 = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>((resolve, reject) =&gt; {
<span class="hljs-comment">// &#x4F7F;&#x7528; settimeout &#x5B9A;&#x65F6;&#x5668;&#x6765;&#x6A21;&#x62DF;&#x5F02;&#x6B65;&#x4EE3;&#x7801;&#x7684;&#x6EDE;&#x540E;&#x6027;</span>
setTimeout(() =&gt; {
  <span class="hljs-comment">// &#x4E00;&#x79D2;&#x540E;&#x4EA7;&#x751F;&#x4E00;&#x4E2A;&#x968F;&#x673A;&#x6570;&#xFF0C;&#x5982;&#x679C;&#x5927;&#x4E8E;0.5&#xFF0C;&#x5219;&#x5C06;promise&#x5B9E;&#x4F8B;&#x53D8;&#x6210;&#x529F;&#xFF0C;&#x53CD;&#x4E4B;&#x53D8;&#x6210;&#x5931;&#x8D25;</span>
  <span class="hljs-keyword">let</span> rdm = <span class="hljs-built_in">Math</span>.random().toFixed(<span class="hljs-number">2</span>);
  <span class="hljs-keyword">if</span> (rdm &gt;= <span class="hljs-number">0.5</span>) {
    <span class="hljs-comment">// &#x53EF;&#x4EE5;&#x5728;&#x72B6;&#x6001;&#x6539;&#x53D8;&#x65F6;&#xFF0C;&#x5C06;&#x6570;&#x636E;&#x4F20;&#x9012;&#x5230;then&#x56DE;&#x8C03;&#x7684;&#x5F62;&#x53C2;&#x4E0A;</span>
    <span class="hljs-comment">// resolve(&#x9700;&#x8981;&#x4F20;&#x9012;&#x5230;then&#x7684;&#x6570;&#x636E;)</span>
    resolve(rdm);
  } <span class="hljs-keyword">else</span> {
    reject(rdm);
  }
}, <span class="hljs-number">1000</span>);
});

<span class="hljs-comment">// pro2.then(&#x6210;&#x529F;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;,[&#x5931;&#x8D25;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;])</span>
pro2
.then(
  <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">data</span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x6570;&#x5B57;&#x5927;&#x4E8E;0.5&quot;</span>, data);
  },
  <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">data</span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x6570;&#x5B57;&#x5C0F;&#x4E8E;0.5&quot;</span>, data);
  }
)
<span class="hljs-comment">// catch &#x7528;&#x4E8E;&#x6355;&#x83B7;&#x4E0A;&#x9762;promise&#x6267;&#x884C;&#x8FC7;&#x7A0B;&#x4EA7;&#x751F;reject&#x6216;&#x8005;&#x62A5;&#x9519;</span>
.catch((err) =&gt; {
  <span class="hljs-built_in">console</span>.log(err);
})
<span class="hljs-comment">// finally:&#x65E0;&#x8BBA;promise&#x5B9E;&#x4F8B;&#x6210;&#x529F;&#x4E0E;&#x5426;&#xFF0C;&#x90FD;&#x4F1A;&#x6267;&#x884C;&#x6700;&#x540E;&#x4E00;&#x6B65;</span>
.finally(() =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x65E0;&#x8BBA;&#x72B6;&#x6001;&#x5982;&#x4F55;&#xFF0C;&#x90FD;&#x4F1A;&#x6267;&#x884C;finally&#x56DE;&#x8C03;&quot;</span>);
});
</code></pre>
<h2 id="promise&#x5C01;&#x88C5;ajax">promise&#x5C01;&#x88C5;ajax</h2>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">_ajax</span>(<span class="hljs-params">{method=&quot;get&quot;,url}</span>)</span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>((resolve,reject)=&gt;{
        <span class="hljs-keyword">let</span> xhr = <span class="hljs-keyword">new</span> XMLHttpRequest();
        xhr.open(method,url);
        xhr.addEventListener(<span class="hljs-string">&quot;readystatechange&quot;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            <span class="hljs-comment">// &#x6CE8;&#x610F;&#xFF0C;readyState &#x4F1A;&#x89E6;&#x53D1;&#x591A;&#x6B21;&#xFF0C;&#x9700;&#x8981;&#x5C06;&#x6761;&#x4EF6;&#x5206;&#x5F00;&#x5199;&#xFF0C;&#x907F;&#x514D;readyState&#x4E3A;2&#x6216;&#x8005;3&#x7684;&#x65F6;&#x5019;&#x5C06;promise&#x72B6;&#x6001;&#x626D;&#x8F6C;&#x4E3A;&#x5931;&#x8D25;</span>
            <span class="hljs-keyword">if</span>(xhr.readyState !== <span class="hljs-number">4</span>){
                <span class="hljs-keyword">return</span>;
            }
            <span class="hljs-keyword">if</span>(xhr.status == <span class="hljs-number">200</span>){
                resolve(<span class="hljs-built_in">JSON</span>.parse(xhr.response));
            }<span class="hljs-keyword">else</span> {
                reject(xhr.status);
            }
        })
        xhr.send();
    })
}
</code></pre>
<h2 id="promiseall">Promise.all</h2>
<ul>
<li>&#x7528;&#x4E8E;&#x7BA1;&#x7406;&#x591A;&#x4E2A; promise &#x5B9E;&#x4F8B;&#xFF0C;&#x5F53;&#x6240;&#x6709;&#x5B9E;&#x4F8B;&#x90FD;&#x6210;&#x529F;&#x65F6;&#xFF0C;&#x624D;&#x6267;&#x884C;&#x6210;&#x529F;&#x56DE;&#x8C03;&#xFF0C;&#x5F53;&#x5176;&#x4E2D;&#x6709;&#x4E00;&#x4E2A;&#x5931;&#x8D25;&#x4E86;&#xFF0C;&#x5219;&#x6267;&#x884C;&#x5931;&#x8D25;&#x56DE;&#x8C03;&#xFF1B;</li>
</ul>
<h2 id="promiseresolve">Promise.resolve</h2>
<ul>
<li>&#x7528;&#x4E8E;&#x5C06;&#x5BF9;&#x8C61;&#x8F6C;&#x5316;&#x4E3A;promise&#x5B9E;&#x4F8B;&#xFF0C;&#x5E76;&#x4E14;&#x72B6;&#x6001;&#x4E3A; resolve;</li>
</ul>
<h2 id="promisereject">Promise.reject</h2>
<ul>
<li>&#x7528;&#x4E8E;&#x5C06;&#x5BF9;&#x8C61;&#x8F6C;&#x5316;&#x4E3A;promise&#x5B9E;&#x4F8B;&#xFF0C;&#x5E76;&#x4E14;&#x72B6;&#x6001;&#x4E3A; reject;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-built_in">Promise</span>.resolve(<span class="hljs-string">&quot;bluej&quot;</span>).then((res) =&gt; {
<span class="hljs-built_in">console</span>.log(res);
});
<span class="hljs-comment">//   &#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x7B49;&#x4EF7;&#x4E8E;</span>
<span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>((resolve, reject) =&gt; {
resolve(<span class="hljs-string">&quot;bgg&quot;</span>);
}).then((res) =&gt; {
<span class="hljs-built_in">console</span>.log(res);
});
</code></pre>
<h2 id="&#x5B9E;&#x73B0;&#x94FE;&#x5F0F;&#x8C03;&#x7528;">&#x5B9E;&#x73B0;&#x94FE;&#x5F0F;&#x8C03;&#x7528;</h2>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> pig = {
eat: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x1F416;&#x5403;&#x996D;&quot;</span>);
  <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>;
},
sleep: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x1F416;&#x7761;&#x89C9;&quot;</span>);
  <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>;
},
};
pig.eat().sleep();
</code></pre>
<h2 id="promiserect">Promise.rect</h2>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">$ajax</span>(<span class="hljs-params">{ method = &quot;get&quot;, url, timeout = 5000 }</span>) </span>{
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">_ajax</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">resolve, reject</span>) </span>{
    <span class="hljs-keyword">let</span> xhr = <span class="hljs-keyword">new</span> XMLHttpRequest();
    xhr.open(method, url);
    xhr.addEventListener(<span class="hljs-string">&quot;readystatechange&quot;</span>, () =&gt; {
      <span class="hljs-keyword">if</span> (xhr.readyState !== <span class="hljs-number">4</span>) {
        <span class="hljs-keyword">return</span>;
      }
      <span class="hljs-keyword">if</span> (xhr.status == <span class="hljs-number">200</span>) {
        resolve(<span class="hljs-built_in">JSON</span>.parse(xhr.response));
      } <span class="hljs-keyword">else</span> {
        reject(xhr.status);
      }
    });
    xhr.send();
  });
}
<span class="hljs-comment">// &#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x7528;&#x4E8E;&#x89E6;&#x53D1;&#x8D85;&#x65F6;&#x7684;promise&#x5B9E;&#x4F8B;</span>
<span class="hljs-keyword">let</span> timer = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>((resolve, reject) =&gt; {
  setTimeout(() =&gt; {
    reject(<span class="hljs-string">&quot;timeout&quot;</span>);
  }, timeout);
});
<span class="hljs-comment">// &#x4F7F;&#x7528;Promise.race&#x5C01;&#x88C5;ajax&#x548C;timer</span>
<span class="hljs-comment">// &#x5982;&#x679C;timer&#x7387;&#x5148;&#x6539;&#x53D8;&#x4E3A;&#x5931;&#x8D25;&#xFF0C;&#x5219;newPro&#x4E5F;&#x4F1A;&#x53D8;&#x6210;&#x5931;&#x8D25;(&#x8D85;&#x65F6;)</span>
<span class="hljs-keyword">return</span> <span class="hljs-built_in">Promise</span>.race([_ajax(), timer]);
}
$ajax({ url: <span class="hljs-string">&quot;https://edu.couchpotato.fun/other/timeout&quot;</span>, timeout: <span class="hljs-number">2000</span> })
.then((res) =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;res&quot;</span>, res);
})
.catch((err) =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;err&quot;</span>, err);
});
</code></pre>
<h2 id="generator-&#x751F;&#x6210;&#x5668;&#x51FD;&#x6570;">Generator &#x751F;&#x6210;&#x5668;&#x51FD;&#x6570;</h2>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span>* <span class="hljs-title">step</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-comment">// yield &#x540E;&#x7EED;&#x7684;&#x8BED;&#x53E5;&#x4F1A;&#x88AB;&#x6682;&#x505C;&#xFF0C;&#x76F4;&#x81F3;&#x4E0B;&#x4E00;&#x6B21; next();</span>
    <span class="hljs-keyword">yield</span> <span class="hljs-string">&quot;step1&quot;</span>;
    <span class="hljs-keyword">yield</span> <span class="hljs-string">&quot;step2&quot;</span>;
    <span class="hljs-keyword">yield</span> <span class="hljs-string">&quot;step3&quot;</span>;
    <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;bgg&quot;</span>;
}
<span class="hljs-comment">// 1.&#x9700;&#x8981;&#x8C03;&#x7528; Generator &#x51FD;&#x6570;&#x5F97;&#x5230;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;</span>
<span class="hljs-keyword">let</span> go = step();
<span class="hljs-built_in">console</span>.log(go);
<span class="hljs-comment">// 2.&#x8C03;&#x7528; next &#x65B9;&#x6CD5;</span>
<span class="hljs-built_in">console</span>.log(go.next());
<span class="hljs-built_in">console</span>.log(go.next());
<span class="hljs-built_in">console</span>.log(go.next());
<span class="hljs-built_in">console</span>.log(go.next());
</code></pre>
<h2 id="async&#x548C;await">async&#x548C;await</h2>
<ul>
<li>js&#x5F02;&#x6B65;&#x7F16;&#x7A0B;&#x7684;&#x7EC8;&#x6781;&#x89E3;&#x51B3;&#x65B9;&#x6848;&#xFF0C;&#x672C;&#x8D28;&#x4E0A;&#x662F;generator</li>
</ul>
<pre><code class="lang-js"><span class="hljs-comment">/* 
1. await &#x5FC5;&#x987B;&#x642D;&#x914D;async&#x4F7F;&#x7528;
2. await &#x5173;&#x952E;&#x5B57;&#x8868;&#x793A;&#x51FD;&#x6570;&#x5FC5;&#x987B;&#x7B49;&#x5F85;&#x53F3;&#x4FA7;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x5B8C;&#x6210;/&#x8FD4;&#x56DE;
3. async &#x5173;&#x952E;&#x5B57;&#x8868;&#x793A;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x53EF;&#x80FD;&#x5305;&#x542B;&#x5F02;&#x6B65;&#x64CD;&#x4F5C;&#xFF0C;&#x914D;&#x5408;await&#x7684;&#x4F7F;&#x7528;
4. &#x4F7F;&#x7528;&#x4E86;async&#x5173;&#x952E;&#x5B57;&#x7684;&#x51FD;&#x6570;&#xFF0C;&#x4F1A;&#x8FD4;&#x56DE;promise,&#x7531;&#x6B64;,&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x7684;return&#x6765;&#x4F20;&#x9012;&#x6570;&#x636E;&#x5230;then&#x5185;
async function test(){
  let data = await _ajax();
  console.log(data);
  // async &#x5185;&#x90E8;return&#x51FA;&#x6765;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x5C06;&#x88AB;test().then()&#x63A5;&#x6536;&#x5230;
  return data;
}
test()
.then()
.catch();
*/</span>

<span class="hljs-comment">/* 
1.await &#x53F3;&#x4FA7;&#x4E3A;&#x6570;&#x636E;&#x65F6;&#xFF0C;&#x76F8;&#x5F53;&#x4E8E;&#x76F4;&#x63A5;&#x8D4B;&#x503C;&#x7ED9;&#x5DE6;&#x4FA7;&#x53D8;&#x91CF;
2.await &#x53F3;&#x4FA7;&#x4E3A;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x65F6;&#xFF0C;&#x4F1A;&#x5C06;&#x51FD;&#x6570;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x7ED9;&#x5230;&#x5DE6;&#x4FA7;&#x53D8;&#x91CF;
3.await &#x53F3;&#x4FA7;&#x4E3A;promise&#x65F6;&#xFF0C;&#x4F1A;&#x7B49;&#x5F85;&#x72B6;&#x6001;&#x626D;&#x8F6C;&#x5E76;&#x4E14;&#x5C06;resolve/reject&#x8C03;&#x7528;&#x65F6;&#x4F20;&#x51FA;&#x6765;&#x7684;&#x6570;&#x636E;&#x7ED9;&#x5230;&#x5DE6;&#x4FA7;&#x53D8;&#x91CF;
*/</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-keyword">return</span> <span class="hljs-string">&quot;class030&quot;</span>;
}
<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-keyword">let</span> data1 = <span class="hljs-keyword">await</span> <span class="hljs-string">&quot;bgg&quot;</span>;
<span class="hljs-keyword">let</span> data2 = <span class="hljs-keyword">await</span> fn();
<span class="hljs-keyword">let</span> data3 = <span class="hljs-keyword">await</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>((resolve) =&gt; {
  setTimeout(() =&gt; {
    resolve(<span class="hljs-string">&quot;&#x6211;&#x6210;&#x529F;&#x4E86;&quot;</span>);
  }, <span class="hljs-number">2000</span>);
});
<span class="hljs-built_in">console</span>.log(data1, data2, data3);
}
test();
</code></pre>
<h2 id="class&#x7C7B;">Class&#x7C7B;</h2>
<ul>
<li>&#x7C7B;&#x4E0E;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x7684;&#x5173;&#x7CFB;:<ol>
<li>&#x7C7B;&#x662F;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x7684;&#x62BD;&#x8C61;&#x548C;&#x63CF;&#x8FF0;</li>
<li>&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x662F;&#x7C7B;&#x7684;&#x5177;&#x8C61;&#x5316;/&#x5B9E;&#x4F8B;&#x5316;&#x7ED3;&#x679C;</li>
</ol>
</li>
<li>&#x57FA;&#x672C;&#x8BED;&#x6CD5;:<pre><code class="lang-js"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Cat</span> </span>{
<span class="hljs-comment">// constructor: &#x6784;&#x9020;&#x51FD;&#x6570;</span>
<span class="hljs-comment">// &#x5BF9;&#x8C61;&#x7279;&#x6709;&#x7684;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#x5728;constructor&#x5185;&#x901A;&#x8FC7;this&#x6DFB;&#x52A0;</span>
<span class="hljs-keyword">constructor</span>(color) {
<span class="hljs-comment">// this&#x8868;&#x793A;&#x5F53;&#x524D;&#x6B63;&#x5728;&#x88AB;&#x521B;&#x5EFA;&#x7684;&#x5B9E;&#x4F8B;</span>
<span class="hljs-keyword">this</span>.color = color;
}
<span class="hljs-comment">// &#x9700;&#x8981;&#x5171;&#x4EAB;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x76F4;&#x63A5;&#x5728;&#x7C7B;&#x91CC;&#x9762;&#x5B9A;&#x4E49;&#x5373;&#x53EF;</span>
eat() {
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x5403;&#x996D;&quot;</span>);
}
<span class="hljs-comment">// static &#x5173;&#x952E;&#x5B57;&#x7528;&#x4E8E;&#x5B9A;&#x4E49;&#x9759;&#x6001;&#x65B9;&#x6CD5;</span>
<span class="hljs-comment">// &#x9759;&#x6001;&#x65B9;&#x6CD5;&#x4E0D;&#x4F1A;&#x88AB;&#x5B9E;&#x4F8B;&#x7EE7;&#x627F;&#xFF0C;&#x53EA;&#x80FD;&#x88AB;&#x7C7B;&#x81EA;&#x8EAB;&#x4F7F;&#x7528;</span>
<span class="hljs-keyword">static</span> test() {
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x9759;&#x6001;&#x65B9;&#x6CD5;&#x76F4;&#x63A5;&#x901A;&#x8FC7;&#x7C7B;&#x6765;&#x8C03;&#x7528;&quot;</span>);
}
<span class="hljs-comment">// &#x9759;&#x6001;&#x5C5E;&#x6027;</span>
<span class="hljs-keyword">static</span> type = <span class="hljs-string">&quot;&#x732B;&#x79D1;&quot;</span>;
}
<span class="hljs-keyword">let</span> cat1 = <span class="hljs-keyword">new</span> Cat(<span class="hljs-string">&quot;&#x6A58;&#x8272;&quot;</span>);
<span class="hljs-keyword">let</span> cat2 = <span class="hljs-keyword">new</span> Cat(<span class="hljs-string">&quot;&#x9ED1;&#x8272;&quot;</span>);
<span class="hljs-built_in">console</span>.log(cat1);
<span class="hljs-comment">// &#x540C;&#x4E00;&#x4E2A;class&#x521B;&#x5EFA;&#x51FA;&#x6765;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x5171;&#x4EAB;&#x540C;&#x4E00;&#x4E2A;&#x539F;&#x578B;&#x5BF9;&#x8C61; &#x548C; &#x539F;&#x578B;&#x94FE;</span>
<span class="hljs-built_in">console</span>.log(cat1.__proto__ == cat2.__proto__); <span class="hljs-comment">// true</span>
<span class="hljs-comment">// &#x9759;&#x6001;&#x65B9;&#x6CD5;&#x76F4;&#x63A5;&#x901A;&#x8FC7;&#x7C7B;&#x81EA;&#x8EAB;&#x8BBF;&#x95EE;</span>
Cat.test();
Cat.type;
</code></pre>
</li>
<li>&#x539F;&#x578B;&#x94FE;&#x7EE7;&#x627F;
```js
// ES5
let Animal = {
eat: function () {
console.log(&quot;&#x5403;&#x996D;&#x4E86;&quot;);
},
sleep: function () {
console.log(&quot;&#x7761;&#x89C9;&#x4E86;&quot;);
},
};
function Cat(color) {
this.color = color;
}
// &#x76F4;&#x63A5;&#x4FEE;&#x6539;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x7684;&#x6307;&#x5411;&#x6765;&#x7EE7;&#x627F;
Cat.prototype = Animal;
// &#x76F4;&#x63A5;&#x6539;&#x53D8;prototype&#x4F1A;&#x5931;&#x53BB;&#x539F;&#x6709;&#x7684;constructor&#x5C5E;&#x6027;&#xFF0C;&#x9700;&#x8981;&#x91CD;&#x65B0;&#x5B9A;&#x5236;&#x4E3A;&#x539F;&#x6784;&#x9020;&#x51FD;&#x6570;
Cat.prototype.constructor = Cat;</li>
</ul>
<p>let cat1 = new Cat(&quot;&#x6A58;&#x8272;&quot;);
console.log(cat1);
/<em> 
ES6 class&#x7684;&#x7EE7;&#x627F;&#x901A;&#x8FC7;extends&#x5173;&#x952E;&#x5B57;&#x6765;&#x5B9E;&#x73B0;&#x7EE7;&#x627F;
&#x6CE8;&#x610F;&#xFF0C;&#x5B50;&#x7C7B;&#x9700;&#x8981;&#x518D;constructor&#x5185;&#x8C03;&#x7528;super();
super():&#x8C03;&#x7528;&#x7236;&#x7C7B;&#x7684;constructor&#x6765;&#x521B;&#x5EFA;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#xFF0C;&#x5E76;&#x5C06;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x8FD4;&#x56DE;&#xFF0C;&#x4F5C;&#x4E3A;&#x5B50;&#x7C7B;&#x7684;this;
tip&#xFF1A;&#x5B50;&#x7C7B;constructor&#x91CC;&#x4E0D;&#x5141;&#x8BB8;&#x5728;super()&#x524D;&#x4F7F;&#x7528;this
</em>/</p>
<p>// &#x7236;&#x7C7B;
class Animal {
constructor(type) {
  this.type = type;
  console.log(37, this);
}
eat() {
  console.log(&quot;&#x5403;&#x996D;&quot;);
}
}
// Cat&#x4F5C;&#x4E3A;&#x5B50;&#x7C7B;&#x53BB;&#x7EE7;&#x627F;Animal&#x7236;&#x7C7B;
class Cat extends Animal {
constructor(type, color) {
  // super&#x5173;&#x952E;&#x5B57;&#x8C03;&#x7528;&#x7236;&#x7C7B;&#x7684;constructor&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF0C;&#x5E76;&#x4E14;&#x5C06;&#x7236;&#x7C7B;&#x6784;&#x9020;&#x51FD;&#x6570;&#x521B;&#x5EFA;&#x7684;&#x5BF9;&#x8C61;&#x8FD4;&#x56DE;&#xFF0C;&#x6210;&#x4E3A;&#x5F53;&#x524D;&#x5B50;&#x7C7B;&#x7684;this&#x5BF9;&#x8C61;
  // super &#x7B49;&#x4E8E; Animal.constructor
  // (&#x73B0;&#x5728;&#x7236;&#x7C7B;&#x751F;&#x6210;&#x5BF9;&#x8C61;&#x5E76;&#x52A0;&#x5DE5;&#xFF0C;&#x518D;&#x7ED9;&#x56DE;&#x5B50;&#x7C7B;&#x7EE7;&#x7EED;&#x52A0;&#x5DE5;)
  // console.log(&quot;&#x4ECE;&#x7236;&#x7C7B;&#x521B;&#x5EFA;this&#x5BF9;&#x8C61;&#x5E76;&#x8FD4;&#x56DE;&quot;, this);
  super(type);
  this.color = color;
  console.log(&quot;&#x52A0;&#x5DE5;&#x5B8C;&#x6210;&quot;, this);
}
}
let cat1 = new Cat(&quot;&#x732B;&#x79D1;&quot;, &quot;&#x9ED1;&#x8272;&quot;);
console.log(cat1);
// &#x901A;&#x8FC7;extends&#x6765;&#x7EE7;&#x627F;&#x7236;&#x7C7B;&#x7684;&#x5C5E;&#x6027;/&#x65B9;&#x6CD5;
console.log(cat1.eat);</p>
<pre><code>* es5&#x6784;&#x9020;&#x7EE7;&#x627F;
```js
function Animal(type) {
this.type = type;
}
Animal.prototype.eat = function () {
console.log(&quot;&#x5403;&#x996D;&#x4E86;&quot;);
};
function Cat(type, color) {
// &#x4F7F;&#x7528;call&#x6765;&#x6307;&#x5B9A;&#x7236;&#x7C7B;Animal&#x7684;this&#x6307;&#x5411;&#xFF0C;&#x73B0;&#x5728;&#x7236;&#x7C7B;Animal&#x91CC;&#x9762;&#x5B8C;&#x6210;&#x5B9E;&#x4F8B;&#x5C5E;&#x6027;/&#x65B9;&#x6CD5;&#x7684;&#x6DFB;&#x52A0;
// &#x5F53;&#x524D;this&#x8868;&#x793A;Cat&#x6B63;&#x5728;&#x88AB;&#x521B;&#x5EFA;&#x7684;&#x5B9E;&#x4F8B;
Animal.call(this, type);
this.color = color;
}
let cat1 = new Cat(&quot;&#x732B;&#x79D1;&quot;, &quot;&#x6A58;&#x8272;&quot;);
console.log(cat1);
</code></pre><ul>
<li>&#x5B50;&#x7C7B;&#x5185;&#x90E8;&#x7684;super&#xFF0C;&#x5728;&#x4E0D;&#x540C;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x4EE3;&#x8868;&#x4E0D;&#x540C;&#x7684;&#x5185;&#x5BB9;<ol>
<li>&#x5728;constructor&#x5185;&#xFF0C;super&#x4EE3;&#x8868;&#x7236;&#x7C7B;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;</li>
<li>&#x5728;&#x5B50;&#x7C7B;&#x539F;&#x578B;&#x51FD;&#x6570;&#x65B9;&#x6CD5;&#x5185;&#xFF0C;super&#x4EE3;&#x8868;&#x7236;&#x7C7B;&#x7684;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#xFF0C;&#x6240;&#x4EE5;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE;&#x7236;&#x7C7B;&#x7684;&#x539F;&#x578B;&#x65B9;&#x6CD5;</li>
<li>&#x5728;&#x5B50;&#x7C7B;&#x7684;&#x9759;&#x6001;&#x65B9;&#x6CD5;&#x5185;&#xFF0C;super.xxx()&#x4F1A;&#x5BF9;&#x5E94;&#x5730;&#x8C03;&#x7528;&#x7236;&#x7C7B;&#x7684;&#x9759;&#x6001;xxx&#x65B9;&#x6CD5;</li>
<li>&#x5982;&#x679C;&#x6CA1;&#x663E;&#x793A;&#x7684;&#x5199;constructor&#xFF0C;&#x5219;&#x4F1A;&#x7531;JS&#x5F15;&#x64CE;&#x81EA;&#x52A8;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x7A7A;&#x7684;constructor&#x51FD;&#x6570;</li>
</ol>
</li>
<li>get&#x548C;set<pre><code class="lang-js"><span class="hljs-comment">// &#x6CE8;&#x610F;&#xFF1A;get set&#x51FD;&#x6570;&#x64CD;&#x4F5C;&#x7684;&#x5C5E;&#x6027;&#x4E0D;&#x80FD;&#x548C;&#x81EA;&#x8EAB;&#x540C;&#x540D;&#xFF0C;&#x4F1A;&#x9020;&#x6210;&#x6B7B;&#x5FAA;&#x73AF;&#xFF0C;&#x5BFC;&#x81F4;&#x8C03;&#x7528;&#x6808;&#x6EA2;&#x51FA;</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Test</span> </span>{
  <span class="hljs-keyword">constructor</span>() {
    <span class="hljs-keyword">this</span>._num = <span class="hljs-number">0</span>;
  }
  <span class="hljs-comment">// &#x8BBE;&#x7F6E;num&#x5C5E;&#x6027;&#x7684;&#x53D6;&#x503C;&#x51FD;&#x6570;</span>
  get num() {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>._num;
  }
  <span class="hljs-comment">// &#x8BBE;&#x7F6E;num&#x5C5E;&#x6027;&#x7684;&#x5B58;&#x503C;&#x51FD;&#x6570;</span>
  set num(newValue) {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x8D4B;&#x503C;&#x5185;&#x5BB9;&quot;</span> + newValue);
    <span class="hljs-comment">// &#x524D;&#x7F6E;&#x6570;&#x636E;&#x8FC7;&#x6EE4;&#x548C;&#x5904;&#x7406;</span>
    <span class="hljs-keyword">if</span> (!<span class="hljs-built_in">isNaN</span>(newValue)) {
      <span class="hljs-keyword">this</span>._num = newValue;
    }
  }
}
<span class="hljs-keyword">let</span> obj = <span class="hljs-keyword">new</span> Test();
obj.num = <span class="hljs-number">88</span>; <span class="hljs-comment">// isNaN&#x901A;&#x8FC7;&#xFF0C;&#x8D4B;&#x503C;&#x6210;&#x529F;</span>
obj.num = <span class="hljs-string">&quot;100aa&quot;</span>; <span class="hljs-comment">// isNaN&#x4E0D;&#x901A;&#x8FC7;&#xFF0C;&#x8D4B;&#x503C;&#x4E0D;&#x6210;&#x529F;</span>
<span class="hljs-built_in">console</span>.log(obj); <span class="hljs-comment">// 0</span>
</code></pre>
</li>
</ul>
<h2 id="&#x9762;&#x5411;&#x5BF9;&#x8C61;">&#x9762;&#x5411;&#x5BF9;&#x8C61;</h2>
<ul>
<li>&#x4F20;&#x7EDF;&#x9762;&#x5411;&#x8FC7;&#x7A0B;&#x7684;&#x7F16;&#x7A0B;&#xFF0C;&#x5B9E;&#x9645;&#x4E0A;&#x662F;&#x4E00;&#x79CD;&#x53D8;&#x91CF;&#x548C;&#x65B9;&#x6CD5;&#x7684;&#x677E;&#x6563;&#x96C6;&#x5408;</li>
<li>&#x9762;&#x5411;&#x5BF9;&#x8C61;&#xFF1A;&#x5C06;&#x53D8;&#x91CF;&#x548C;&#x51FD;&#x6570;&#xFF0C;&#x62BD;&#x8C61;&#x6210;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#xFF0C;&#x6240;&#x6709;&#x7684;&#x64CD;&#x4F5C;&#x90FD;&#x662F;&#x57FA;&#x4E8E;&#x5BF9;&#x8C61;&#xFF0C;&#x9762;&#x5411;&#x5BF9;&#x8C61;&#x5C06;&#x5927;&#x5E45;&#x63D0;&#x5347;&#x6211;&#x4EEC;&#x4EE3;&#x7801;&#x7684;&#x53EF;&#x9605;&#x8BFB;&#x6027;&#x548C;&#x7EF4;&#x62A4;&#x80FD;&#x529B;</li>
<li>&#x4E00;.&#x5C01;&#x88C5;&#xFF1A;&#x4E0D;&#x9700;&#x8981;&#x5728;&#x77E5;&#x9053;&#x5177;&#x4F53;&#x5B9E;&#x73B0;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x5373;&#x53EF;&#x4F7F;&#x7528;&#x76F8;&#x5E94;&#x7684;&#x65B9;&#x6CD5;&#x4E14;&#x53EF;&#x4EE5;&#x88AB;&#x590D;&#x7528;</li>
<li>&#x4E8C;.&#x7EE7;&#x627F;&#xFF1A;&#x5B50;&#x7C7B;&#x4ECE;&#x7236;&#x7C7B;&#x4E0A;&#x7EE7;&#x627F;&#x7279;&#x8D28;(&#x5C5E;&#x6027;/&#x65B9;&#x6CD5;)</li>
<li>&#x4E09;.&#x591A;&#x6001;&#xFF1A;&#x4E0D;&#x540C;&#x7684;&#x7C7B;&#x53EF;&#x4EE5;&#x62E5;&#x6709;&#x76F8;&#x540C;&#x7684;&#x65B9;&#x6CD5;&#x540D;&#x79F0;&#xFF0C;&#x4F46;&#x662F;&#x5177;&#x4F53;&#x5B9E;&#x73B0;&#x53EF;&#x4EE5;&#x4E0D;&#x540C;</li>
</ul>
<h2 id="&#x6A21;&#x5757;&#x5316;">&#x6A21;&#x5757;&#x5316;</h2>
<ul>
<li>html&#x4F7F;&#x7528;es6&#x6A21;&#x5757;&#x5316;&#x65F6;&#xFF0C;&#x9700;&#x8981;&#x5728;script&#x4E0A;&#xFF0C;&#x52A0;&#x4E0A;type = &quot;module&quot;
```js
// &#x4F7F;&#x7528;import&#x6765;&#x5BFC;&#x5165;&#x5BF9;&#x5E94;&#x7684;&#x53D8;&#x91CF;
// &#x4F7F;&#x7528;as&#x5173;&#x952E;&#x5B57;&#x5728;&#x5BFC;&#x5165;&#x53D8;&#x91CF;&#x65F6;&#x63D0;&#x4F9B;&#x522B;&#x540D;
import { money, item as run } from &quot;./a.js&quot;;
console.log(money, run);</li>
</ul>
<p>// &#x6574;&#x4F53;&#x5F15;&#x5165;,&#x4F7F;&#x7528;<em>&#x8868;&#x793A;&#x5C06;&#x76EE;&#x6807;&#x6A21;&#x5757;&#x7684;&#x6240;&#x6709;&#x5BFC;&#x51FA;&#x5168;&#x90E8;&#x5BFC;&#x5165;
// &#x6CE8;&#x610F;&#xFF1A;&#x9700;&#x8981;&#x4E3A; </em> &#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x522B;&#x540D;&#x624D;&#x80FD;&#x6B63;&#x5E38;&#x4F7F;&#x7528;
import * as b_obj from &quot;./b.js&quot;;
console.log(b_obj);
console.log(b_obj.str);</p>
<p>// default&#x5BFC;&#x51FA;&#x7684;&#x5185;&#x5BB9;&#xFF0C;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x5BFC;&#x5165;
// &#x4E0D;&#x9700;&#x8981;&#x901A;&#x8FC7;{}&#x53BB;&#x5BFC;&#x5165;&#xFF0C;&#x66F4;&#x52A0;&#x5FEB;&#x901F;&#x7B80;&#x4FBF;
import value from &quot;./c.js&quot;;
console.log(&quot;&#x9ED8;&#x8BA4;&#x5BFC;&#x5165;&quot;, value);
// &#x5185;&#x90E8;&#x8FC7;&#x7A0B;&#x5982;&#x4E0B;&#xFF1A;
import {default as value} from &quot;./c.js&quot;</p>
<pre><code>
## Set

* ES6&#x65B0;&#x589E;&#x6570;&#x636E;&#x7ED3;&#x6784;&#xFF0C;&#x7C7B;&#x6570;&#x7EC4;&#xFF0C;&#x6210;&#x5458;&#x552F;&#x4E00;&#x4E0D;&#x53EF;&#x91CD;&#x590D;,&#x5E38;&#x7528;&#x4E8E;&#x5FEB;&#x901F;&#x53BB;&#x91CD;
 1. set.add(): &#x7528;&#x4E8E;&#x5411;set&#x5B9E;&#x4F8B;&#x6DFB;&#x52A0;&#x6210;&#x5458;&#xFF0C;&#x8FD4;&#x56DE;set&#x5B9E;&#x4F8B;
 2. set.has(): &#x7528;&#x4E8E;&#x5224;&#x65AD;set&#x5B9E;&#x4F8B;&#x662F;&#x5426;&#x62E5;&#x6709;&#x6307;&#x5B9A;&#x6210;&#x5458;&#xFF0C;&#x8FD4;&#x56DE;true/false
 3. set.delete(): &#x7528;&#x4E8E;&#x5220;&#x9664;set&#x5B9E;&#x4F8B;&#x6210;&#x5458;&#xFF0C;&#x8FD4;&#x56DE;true/false&#x8868;&#x793A;&#x662F;&#x5426;&#x5220;&#x9664;&#x6210;&#x529F;
 4. set.clear(): &#x6E05;&#x9664;set&#x5B9E;&#x4F8B;&#x6240;&#x6709;&#x6210;&#x5458;

## Map

* Map&#x76F8;&#x5BF9;&#x4E8E;&#x4F20;&#x7EDF;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x952E;&#x503C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x5F15;&#x7528;&#x6570;&#x636E;&#x7C7B;&#x578B;
 1. set(key,value): &#x4E3A;map&#x5B9E;&#x4F8B;&#x6DFB;&#x52A0;&#x952E;&#x503C;&#x5BF9;&#x6210;&#x5458;
 2. &#x4F7F;&#x7528;get(key)&#x6765;&#x8BFB;&#x53D6;attr&#x7684;&#x63CF;&#x8FF0;
 3. has(key): &#x5224;&#x65AD;&#x662F;&#x5426;&#x62E5;&#x6709;&#x6307;&#x5B9A;key&#x7684;&#x5B58;&#x5728;
 4. delete(key): &#x5220;&#x9664;&#x6307;&#x5B9A;key
 5. clear(): &#x6E05;&#x9664;map&#x5B9E;&#x4F8B;

## Object.defineProperty(&#x8981;&#x64CD;&#x4F5C;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x8981;&#x8BBE;&#x7F6E;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x76F8;&#x5173;&#x8BBE;&#x7F6E;)

```js
let data = {};
let _data = {};
let ipt = document.querySelector(&quot;.ipt&quot;);
ipt.addEventListener(&quot;input&quot;, function () {
    data.iptVal = this.value;
});
Object.defineProperty(data, &quot;iptVal&quot;, {
    // &#x8BBE;&#x7F6E;/&#x90E8;&#x7F72; &#x5C5E;&#x6027;&#x7684;&#x8D4B;&#x503C;&#x62E6;&#x622A;&#x5668;
    set(newValue) {
      ipt.value = newValue;
      _data.iptVal = newValue;
      // &#x6CE8;&#x610F;&#xFF0C;&#x4E0D;&#x8981;&#x5728;&#x5C5E;&#x6027;&#x7684;&#x8D4B;&#x503C;&#x51FD;&#x6570;&#x5185;&#x7EE7;&#x7EED;&#x8D4B;&#x503C;&#x7ED9;&#x81EA;&#x5DF1;
      // &#x907F;&#x514D;&#x4EA7;&#x751F;&#x6B7B;&#x5FAA;&#x73AF;
      // data.iptVal = newValue;
    },
    // &#x5C5E;&#x6027;&#x7684;&#x53D6;&#x503C;&#x62E6;&#x622A;&#x5668;&#xFF0C;&#x5F53;&#x6211;&#x4EEC;&#x8BBF;&#x95EE;data.iptVal&#x65F6;&#xFF0C;&#x89E6;&#x53D1;get&#x51FD;&#x6570;
    get() {
      return _data.iptVal;
    },
});
</code></pre><h2 id="&#x5C01;&#x88C5;&#x9632;&#x6296;">&#x5C01;&#x88C5;&#x9632;&#x6296;</h2>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">debounce</span>(<span class="hljs-params">fn, timeout = 500</span>) </span>{
    <span class="hljs-keyword">let</span> timer;
    <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
      <span class="hljs-keyword">if</span> (timer) {
        clearTimeout(timer);
      }
      timer = setTimeout(() =&gt; {
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x7BAD;&#x5934;&#x51FD;&#x6570;&quot;</span>, <span class="hljs-keyword">this</span>, <span class="hljs-built_in">arguments</span>);
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x4E1A;&#x52A1;&#x4EE3;&#x7801;&quot;</span>);
        <span class="hljs-comment">// &#x5C06;&#x4E1A;&#x52A1;&#x4EE3;&#x7801;&#x4F20;&#x8FDB;&#x6765;&#xFF0C;&#x8BA9;&#x9632;&#x6296;&#x51FD;&#x6570;&#x53EF;&#x4EE5;&#x9002;&#x7528;&#x4E8E;&#x591A;&#x4E2A;&#x4E1A;&#x52A1;&#x573A;&#x666F;</span>
        <span class="hljs-comment">// &#x5C06;this&#x548C;arguments&#x4F20;&#x8FDB;&#x53BB;&#xFF0C;&#x4FEE;&#x6B63;&#x4E1A;&#x52A1;&#x4EE3;&#x7801;&#x5185;this&#x548C;arguments&#x7684;&#x6307;&#x5411;</span>
        fn.apply(<span class="hljs-keyword">this</span>, <span class="hljs-built_in">arguments</span>);
      }, timeout);
    };
}
</code></pre>
<h2 id="&#x5C01;&#x88C5;&#x8282;&#x6D41;">&#x5C01;&#x88C5;&#x8282;&#x6D41;</h2>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">throttle</span>(<span class="hljs-params">fn, timeout = 500</span>) </span>{
    <span class="hljs-keyword">let</span> canRun = <span class="hljs-literal">true</span>;
    <span class="hljs-comment">// &#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x4F5C;&#x4E3A;&#x540E;&#x7EED;&#x7684;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;</span>
    <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
      <span class="hljs-keyword">if</span> (canRun) {
        canRun = <span class="hljs-literal">false</span>;
        <span class="hljs-comment">// &#x4E1A;&#x52A1;&#x4EE3;&#x7801;</span>
        fn.apply(<span class="hljs-keyword">this</span>, <span class="hljs-built_in">arguments</span>);
        setTimeout(() =&gt; {
          canRun = <span class="hljs-literal">true</span>;
        }, timeout);
      }
    };
}
</code></pre>
<h2 id="&#x5783;&#x573E;&#x56DE;&#x6536;&#x673A;&#x5236;">&#x5783;&#x573E;&#x56DE;&#x6536;&#x673A;&#x5236;</h2>
<ul>
<li>&#x6807;&#x8BB0;&#x6E05;&#x9664;&#xFF1A;JS&#x6267;&#x884C;&#x5230;&#x51FD;&#x6570;&#x5185;&#x65F6;&#xFF0C;&#x4F1A;&#x5C06;&#x5BF9;&#x5E94;&#x4F5C;&#x7528;&#x57DF;&#x4E0B;&#x7684;&#x53D8;&#x91CF;&#x6807;&#x8BC6;&#x4E3A;&#x53EF;&#x7528;&#x72B6;&#x6001;&#xFF0C;&#x5F53;&#x51FD;&#x6570;&#x6267;&#x884C;&#x7ED3;&#x675F;&#x65F6;&#xFF0C;js&#x5F15;&#x64CE;&#x4F1A;&#x5C06;&#x51FD;&#x6570;&#x5185;&#x7684;&#x53D8;&#x91CF;&#x6807;&#x8BC6;&#x4E3A;&#x4E0D;&#x53EF;&#x7528;&#xFF0C;&#x5783;&#x573E;&#x56DE;&#x6536;&#x673A;&#x5236;&#x4F1A;&#x5B9A;&#x671F;&#x56DE;&#x6536;&#x6389;&#xFF0C;&#x4E0D;&#x53EF;&#x7528;&#x7684;&#x53D8;&#x91CF;&#x8FDB;&#x884C;&#x9500;&#x6BC1;&#xFF0C;&#x4EE5;&#x89E3;&#x9664;&#x5185;&#x5B58;&#x5360;&#x7528;&#xFF1B;</li>
<li>&#x5F15;&#x7528;&#x8BA1;&#x6570;&#xFF1A;<pre><code class="lang-js"><span class="hljs-comment">// &#x6839;&#x636E;&#x503C;&#x7684;&#x5F15;&#x7528;&#x6B21;&#x6570;&#x662F;&#x5426;&#x4E3A;0&#x6765;&#x5224;&#x65AD;&#xFF0C;&#x662F;&#x5426;&#x8981;&#x8FDB;&#x884C;&#x56DE;&#x6536;</span>
<span class="hljs-keyword">let</span> obj1 = {}; <span class="hljs-comment">// &#x5F15;&#x7528;&#x6B21;&#x6570;1</span>
<span class="hljs-keyword">let</span> obj2 = obj1; <span class="hljs-comment">// &#x5F15;&#x7528;&#x6B21;&#x6570;2</span>
<span class="hljs-comment">// &#x65AD;&#x5F00;&#x5F15;&#x7528;&#x8FDB;&#x884C;&#x56DE;&#x6536;</span>
<span class="hljs-keyword">let</span> obj1 = obj2 = <span class="hljs-literal">null</span>;
</code></pre>
</li>
<li>&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x4F1A;&#x4E00;&#x76F4;&#x5B58;&#x5728;&#xFF0C;&#x9664;&#x975E;&#x628A;&#x5B83;&#x8D4B;&#x503C;&#x4E3A;null/undefined&#xFF0C;&#x624D;&#x4F1A;&#x88AB;&#x56DE;&#x6536;&#x673A;&#x5236;&#x56DE;&#x6536;</li>
<li>&#x968F;&#x7740;&#x51FD;&#x6570;&#x7684;&#x8C03;&#x7528;&#xFF0C;&#x4F5C;&#x7528;&#x57DF;&#x968F;&#x4E4B;&#x4EA7;&#x751F;&#xFF0C;&#x540C;&#x65F6;&#xFF0C;&#x51FD;&#x6570;&#x5185;&#x7684;&#x53D8;&#x91CF;/&#x51FD;&#x6570;&#x88AB;&#x6FC0;&#x6D3B;&#xFF0C;&#x5904;&#x4E8E;&#x6D3B;&#x8DC3;&#xFF0C;&#x53EF;&#x7528;&#x7684;&#x72B6;&#x6001;,&#x968F;&#x7740;&#x51FD;&#x6570;&#x6267;&#x884C;&#x7684;&#x7ED3;&#x675F;&#xFF0C;&#x51FD;&#x6570;&#x5185;&#x7684;&#x53D8;&#x91CF;&#x4F1A;&#x88AB;&#x56DE;&#x6536;/&#x9500;&#x6BC1;</li>
</ul>
<h2 id="&#x95ED;&#x5305;">&#x95ED;&#x5305;</h2>
<pre><code class="lang-js"><span class="hljs-comment">// &#x4F5C;&#x7528;&#x57DF;&#x89C4;&#x5219;&#xFF1A;&#x5F53; JS &#x5F15;&#x64CE;&#x6267;&#x884C;&#x51FD;&#x6570;&#x5230;&#x7ED3;&#x675F;&#x65F6;&#xFF0C;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x7684;&#x53D8;&#x91CF;&#x4F1A;&#x88AB;&#x9500;&#x6BC1;&#x56DE;&#x6536;</span>
<span class="hljs-comment">// &#x95ED;&#x5305;&#xFF1A;&#x5C06;&#x51FD;&#x6570;&#x5185;&#x7684; &#x53D8;&#x91CF; &#x5F15;&#x7528;&#xFF0C;&#x8FD4;&#x56DE;&#x81F3; &#x51FD;&#x6570;&#x5916;&#x90E8;&#xFF0C;&#x4FDD;&#x6301;&#x4E86; &#x53D8;&#x91CF; &#x7684;&#x6301;&#x7EED;&#x5F15;&#x7528;</span>
<span class="hljs-comment">// &#x6CE8;&#x610F;&#xFF1A;&#x5982;&#x679C;&#x4E0D;&#x5BF9;&#x95ED;&#x5305;&#x7684;&#x5185;&#x5BB9;&#x8FDB;&#x884C;&#x56DE;&#x6536;&#xFF0C;&#x90A3;&#x4E48;&#xFF0C;&#x95ED;&#x5305;&#x7684;&#x5F15;&#x7528;&#x4F1A;&#x4E00;&#x76F4;&#x4FDD;&#x6301;&#x5728;&#x5185;&#x5B58;&#x91CC;&#xFF0C;&#x6240;&#x4EE5;&#xFF0C;&#x6CE8;&#x610F;&#x4E0D;&#x8981;&#x6EE5;&#x7528;&#x95ED;&#x5305;</span>

<span class="hljs-comment">// function _ajax() {</span>
<span class="hljs-comment">//   new Promise();</span>
<span class="hljs-comment">//   // &#x5982;&#x679C;&#x4E0D;return&#x8BE5;promise&#xFF0C;&#x90A3;&#x4E48;&#x51FD;&#x6570;&#x4E00;&#x6267;&#x884C;&#x7ED3;&#x675F;&#xFF0C;&#x8BE5;promise&#x5C31;&#x4F1A;&#x88AB;&#x56DE;&#x6536;&#xFF1B;</span>
<span class="hljs-comment">// }</span>
<span class="hljs-comment">// &#x6240;&#x4EE5;&#xFF0C;ajax&#x5C01;&#x88C5;&#x7684;&#x5B9E;&#x73B0;&#xFF0C;&#x5C31;&#x662F;&#x5229;&#x7528;&#x4E86;&#x95ED;&#x5305;&#x7684;&#x539F;&#x7406;&#xFF0C;&#x6765;&#x8BA9;&#x5916;&#x90E8;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE;promise&#x5B9E;&#x4F8B;&#xFF0C;&#x4ECE;&#x800C;&#x53EF;&#x4EE5;&#x5728;&#x5916;&#x90E8;&#x53BB;&#x6DFB;&#x52A0;.then .catch&#x7B49;&#x64CD;&#x4F5C;</span>
<span class="hljs-comment">// function _ajax() {</span>
<span class="hljs-comment">//   return new Promise(function(){</span>
<span class="hljs-comment">//     ...</span>
<span class="hljs-comment">//   })</span>
<span class="hljs-comment">// }</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn1</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-keyword">let</span> i = <span class="hljs-number">10</span>;
<span class="hljs-keyword">return</span> i;
}
<span class="hljs-keyword">let</span> res1 = fn1();
<span class="hljs-comment">/* &#x8FC7;&#x7A0B; 
  &#x6B64;&#x5904;&#x4E0D;&#x5B58;&#x5728;&#x95ED;&#x5305;&#xFF0C;&#x8FD4;&#x56DE;&#x57FA;&#x672C;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x65F6;&#xFF0C;&#x53EA;&#x662F;&#x7B80;&#x5355;&#x8D4B;&#x4E88;&#x4E86;&#x4E00;&#x4E2A;&#x6808;&#x5185;&#x5B58;&#x7684;&#x503C;&#xFF1B;
  &#x76F8;&#x5F53;&#x4E8E;&#x76F4;&#x63A5; = 10&#xFF0C;&#x6CA1;&#x6709; &#x5F15;&#x7528; &#x7684;&#x590D;&#x5236;
  let res1 = 10
*/</span>
</code></pre>

                                
                                </section>
                            
                        </div>
                    </div>
                
            </div>

            
                
                <a href="nvm.html" class="navigation navigation-prev " aria-label="Previous page: nvm">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="ES6-ES11.html" class="navigation navigation-next " aria-label="Next page: ES6-ES11">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"ES6","level":"1.4.21","depth":2,"next":{"title":"ES6-ES11","level":"1.4.22","depth":2,"path":"md/03js/ES6-ES11.md","ref":"./md/03js/ES6-ES11.md","articles":[]},"previous":{"title":"nvm","level":"1.4.20","depth":2,"path":"md/03js/nvm.md","ref":"./md/03js/nvm.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","-sharing","toggle-chapters","image-captions","-anchor-navigation","-anchor-navigation-ex"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"image-captions":{"attributes":{"style":"left: 50%;position: relative;transform: translateX(-50%);"},"caption":"图 _PAGE_LEVEL_._PAGE_IMAGE_NUMBER_ - _CAPTION_","align":"center","variable_name":"_pictures"},"fontsettings":{"theme":"night","family":"sans","size":2},"toggle-chapters":{},"highlight":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"Landen","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{"_pictures":[]},"gitbook":"3.x.x"},"file":{"path":"md/03js/ES6.md","mtime":"2020-08-17T09:39:02.201Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-08-17T10:41:18.504Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-toggle-chapters/toggle.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

